# -*- coding: utf-8 -*-
from django.db import models
from django.conf import settings
from django.utils.translation import ugettext as _
from djwheel.adminutils import create_preview_field, create_link_field
from djwheel.langutils import merge_attrs
import appsettings

settings = merge_attrs(settings, appsettings)

class Images(models.Model):
    image = models.ImageField(_('Image'), upload_to=settings.MEDIASTORAGE_IMAGES_UPLOAD_TO)
    description = models.CharField(_('Description'), max_length=512)
    preview_image = create_preview_field(_('Preview'), 'image', 'description')
    adm_preview_image = create_preview_field(_('Preview'), 'image', 'description',
        max_size=(800, 1000))

    def adm_path(self):
        return self.image.url
    adm_path.short_description = _('image path')

    def adm_code(self):
        return unicode(self.preview_image())
    adm_code.short_description = _('HTML')

    class Meta:
        verbose_name = _('image')
        verbose_name_plural = _('images')

    def __unicode__(self):
        return self.description


class Files(models.Model):
    file = models.FileField(_('File'), upload_to=settings.MEDIASTORAGE_FILES_UPLOAD_TO)
    description = models.CharField(_('Description'), max_length=512)
    link = create_link_field(_('Link'), 'file', 'description')

    def adm_code(self):
        return u'<a href="%s">%s</a>' % (self.link(), self.description)
    adm_code.short_description = _('code')

    def __unicode__(self):
        return self.description

    class Meta:
        verbose_name = _('file')
        verbose_name_plural = _('files')

